package com.mosai.smartmedical.entity;

import android.app.Notification;
import android.os.Build;
import android.os.Bundle;
import android.service.notification.StatusBarNotification;

/**
 * Created by Rays on 2020/12/10.
 */
public class NotificationListenerEvent {
    public static final int TYPE_CONNECTED = 1;
    public static final int TYPE_DISCONNECTED = 2;
    public static final int TYPE_POSTED = 3;
    public static final int TYPE_REMOVED = 4;

    public int type;
    public int id;
    public String tag;
    public String key;
    public String groupKey;
    public String channelId;
    public String pkg;
    public String title;
    public String text;

    public NotificationListenerEvent(int type) {
        this(type, null);
    }

    public NotificationListenerEvent(int type, StatusBarNotification sbn) {
        this.type = type;
        if (sbn != null) {
            pkg = sbn.getPackageName();
            id = sbn.getId();
            tag = sbn.getTag();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
                key = sbn.getKey();
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    groupKey = sbn.getGroupKey();
                }
            }
            Notification notification = sbn.getNotification();

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                channelId = notification.getChannelId();
            }

            Bundle extras = notification.extras;
            title = extras.getString(Notification.EXTRA_TITLE);
            text = extras.getString(Notification.EXTRA_TEXT);
        }
    }
}
